package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbTaskReportingVo;
import com.ruoyi.tb.lmt.domain.bo.TbTaskReportingBo;
import com.ruoyi.tb.lmt.service.ITbTaskReportingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务报工
 *
 * @author ruoyi
 * @date 2024-04-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/taskReporting")
public class TbTaskReportingController extends BaseController {

    private final ITbTaskReportingService iTbTaskReportingService;

    /**
     * 查询任务报工列表
     */
    @GetMapping("/list")
    public TableDataInfo<TbTaskReportingVo> list(TbTaskReportingBo bo, PageQuery pageQuery) {
        return iTbTaskReportingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出任务报工列表
     */
    @Log(title = "任务报工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbTaskReportingBo bo, HttpServletResponse response) {
        List<TbTaskReportingVo> list = iTbTaskReportingService.queryList(bo);
        ExcelUtil.exportExcel(list, "任务报工", TbTaskReportingVo.class, response);
    }

    /**
     * 获取任务报工详细信息
     *
     * @param ID 主键
     */
    @GetMapping("/{ID}")
    public R<TbTaskReportingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbTaskReportingService.queryById(ID));
    }

    /**
     * 新增任务报工
     */
    @Log(title = "任务报工", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbTaskReportingBo bo) {
        return toAjax(iTbTaskReportingService.insertByBo(bo));
    }

    /**
     * 修改任务报工
     */
    @Log(title = "任务报工", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbTaskReportingBo bo) {
        return toAjax(iTbTaskReportingService.updateByBo(bo));
    }

    /**
     * 删除任务报工
     *
     * @param IDs 主键串
     */
    @Log(title = "任务报工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbTaskReportingService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }

    /**
     * 查询任务报工列表
     */
    @GetMapping("/selectList")
    public List<TbTaskReportingVo> list() {
        return iTbTaskReportingService.selectList();
    }
}
